package com.czk.tx.transactiontemplate;

import com.czk.tx.dao.MoneyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * 编程式事务TransactionTemplate的使用
 *
 * @Author:ChenZhangKun
 * @Date: 2021/9/10 17:26
 */
@Service
public class TransactionTemplateService {
    @Autowired
    private MoneyDao moneyDao;
    @Autowired
    private TransactionTemplate transactionTemplate;

    public void test() {
        transactionTemplate.execute(status -> {
                    moneyDao.add();
                    moneyDao.reduce();
                    return "执行成功";
                }
        );
    }
}
